/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PlaylistCellWithArtPanel.java
 *
 * Created on Mar 8, 2009, 2:36:51 PM
 */
package com.bff.slimserver.musicjukebox.ui.components.favorites;

import com.bff.bjj.ui.component.ColorProperties;
import com.bff.slimserver.musicjukebox.lib.JukeboxProperties;
import com.bff.bjj.ui.component.BJJPanel;
import java.awt.Color;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bff.slimserver.SlimServer;
import org.bff.slimserver.exception.SlimConnectionException;
import org.bff.slimserver.musicobjects.radio.SlimAvailableRadio;

/**
 *
 * @author Music
 */
public class FavoritesCellSearchPanel extends BJJPanel implements FavoritesCellPanelIface {

    private SlimServer slimServer;
    private SlimAvailableRadio radio;

    /** Creates new form PlaylistCellWithArtPanel */
    public FavoritesCellSearchPanel(SlimAvailableRadio radio) {
        setRadio(radio);
        try {
            setSlimServer(JukeboxProperties.getInstance().getSlimServer());
        } catch (SlimConnectionException ex) {
            Logger.getLogger(FavoritesCellSearchPanel.class.getName()).log(Level.SEVERE, null, ex);
        }
        initComponents();

        Timer timer = new Timer(1000, new TimerListener());
        timer.setInitialDelay(0);
        timer.start();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        tfSearchCriteria = new javax.swing.JTextField();
        btnSearch = new javax.swing.JButton();

        setLayout(new java.awt.BorderLayout());

        tfSearchCriteria.setColumns(20);
        add(tfSearchCriteria, java.awt.BorderLayout.CENTER);

        btnSearch.setFont(new java.awt.Font("Tahoma", 0, 10));
        btnSearch.setText("Search");
        add(btnSearch, java.awt.BorderLayout.EAST);
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnSearch;
    private javax.swing.JTextField tfSearchCriteria;
    // End of variables declaration//GEN-END:variables

    public void setEven() {
        setBackground(ColorProperties.LIST_BACKGROUND_EVEN);
    }

    public void setOdd() {
        setBackground(ColorProperties.LIST_BACKGROUND_ODD);
    }

    public void setCurrentPlaying() {
        setForeground(ColorProperties.PLAYLIST_CURRENT_PLAYING_FOREGROUND);
    }

    public void setSelected() {
        setForeground(ColorProperties.LIST_FOREGROUND_SELECTED);
        setBackground(ColorProperties.LIST_BACKGROUND_SELECTED);
    }

    public void setNotSelected() {
        setForeground(ColorProperties.LIST_FOREGROUND);
    }

    @Override
    public void setBackground(Color bg) {
        super.setBackground(bg);
        //detailPanel.setBackground(bg);
//        if (detailPanel != null) {
//            detailPanel.setBackground(bg);
//            lblIcon.setBackground(bg);
//        }
    }

    @Override
    public void setForeground(Color fg) {
        super.setForeground(fg);
//        if (detailPanel != null) {
//            detailPanel.setForeground(fg);
//            lblIcon.setForeground(fg);
//        }
        setLabelColors(fg);
    }

    private void setLabelColors(Color color) {
//        if (lblIcon != null) {
//            lblName.setForeground(color);
//            lblIcon.setForeground(color);
//        }
    }

    @Override
    public Component getPanel() {
        return this;
    }

    public void setCurrent() {
        setLabelColors(ColorProperties.PLAYLIST_CURRENT_PLAYING_FOREGROUND);
    }

    public void setNotCurrent() {
        setLabelColors(ColorProperties.LIST_FOREGROUND_SELECTED);
    }

    /**
     * @return the radio
     */
    public SlimAvailableRadio getRadio() {
        return radio;
    }

    /**
     * @param radio the radio to set
     */
    public void setRadio(SlimAvailableRadio radio) {
        this.radio = radio;
    }

    /**
     * @return the slimServer
     */
    public SlimServer getSlimServer() {
        return slimServer;
    }

    /**
     * @param slimServer the slimServer to set
     */
    public void setSlimServer(SlimServer slimServer) {
        this.slimServer = slimServer;
    }

    private class TimerListener implements ActionListener {
        private Color bg;
        private Color fg;
        private boolean isForeground;

        public TimerListener() {
            bg = btnSearch.getBackground();
            fg = btnSearch.getForeground();
        }
        
        public void actionPerformed(ActionEvent e) {

            if(isForeground) {
                btnSearch.setForeground(bg);
                btnSearch.setBackground(fg);
            } else {
                btnSearch.setForeground(fg);
                btnSearch.setBackground(bg);
            }

            isForeground = !isForeground;
        }


    }
}